
<?php
require_once '../include.php';

$PG = new pgsql("gis24.jlu3s.com", "23456", "ccly", "sde", "GIScontest2024");  
$PG->connect(); 
if(!$PG){  
    $db_error = "无法连接到PostGreSQL数据库！";  
    echo $db_error;   
}else{
    $query = "SELECT * FROM public.region";
    $rows = $PG->fetchAll($query);
} 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加用户</title>
<style>
    tr{
        line-height: 50px;
    }
</style>
</head>

<body>
	<div style="padding: 15px 15px;" class="details">
		<h2>添加用户</h2>
		<form action="doAddUser.php" method="post"  id="reg" name="reg" onsubmit="return checksubmit()" >
            
			<table class="table" cellspacing="0" cellpadding="0">
            <tr>
                <td align="right"><span style="color:red;">*</span> 姓名：</td>
                <td><input type="text" name="name" class=" :wait;5500 :min_length;2 " /><span style="color:blue;font-size:12px;">[注意:请输入真实姓名，以便更好地沟通]</span></td>
            </tr>	
            <tr>
                <td align="right"><span style="color:red;">*</span> 性别：</td>
                <td><div class="input_item">
                        <input type="radio"  name="gender" value="1"> 男
                        <input type="radio"  checked="checked" name="gender" value="2" > 女
                        <input type="radio"  name="gender" value="0"> 未知
                    </div>
                </td>
            </tr>
            <tr>
                <td align="right">电话（手机号）：</td>
                <td><input type="text" name="phone"  id="phone" /></td>
            </tr>
            <tr>
                <td align="right">电子邮箱：</td>
                <td><input type="text" name="email"  id="email" /></td>
            </tr>
            <tr>
                <td align="right"><span style="color:red;">*</span> 家乡：</td>
                <td>
                <select name="area_code" >                       
                        <?php if(is_null($rows)){ echo "未查到相关数据";}else{ foreach($rows as $row): ?>
                            <option value="<?php echo $row['prov_code'];?>" <?php echo $row['prov_code']=='220000'?"selected='selected'":null;?>><?php echo $row['prov_name']; ?></option>
                        <?php endforeach;} ?>    
                </select>
                </td>
            </tr>
            <tr>
                <td width="10%" align="right">描述(限500字)：</td>
                <td><textarea type="text" cols="100" rows="3" name="description" style="border: 1px solid #999;"></textarea></td>
			</tr>
            <tr>
                <td align="right"><span style="color:red;">*</span> 用户名：</td>
                <td><input type="text" name="username" /><span style="color:blue;font-size:12px;">[注意:不能与别人重复；注册后不能随便更改）]</span></td>
            </tr>
            <tr>
                <td align="right"><span style="color:red;">*</span>密码：</td>
                <td width="80%"><input type="password" name="password"  id="pass"/></td>
            </tr>
            <tr>
                <td align="right"><span style="color:red;">*</span>确认密码：</td>
                <td><input type="password" name="password2" id="pass2"/></td>
            </tr>
            <tr>
                <td align="right"><span style="color:red;">*</span>设置角色权限：</td>
                <td>
                <select name="power_id" >                       
                    <option value="1" selected="selected">普通用户</option>
                    <option value="0" >管理员</option>  
                    <option value="2" >冻结/禁用</option> 
                </select>
                </td>
            </tr>
            <tr align="left">
                <td colspan="2" >
                    <input type="submit" value="提  交"  class="btn" style="cursor: pointer; height: 30px; width: 100px" />&nbsp;&nbsp;
                    <input type="button" value="取  消" class="btn" onclick="Cancel()" style="cursor: pointer; height: 20px; width: 80px" />
                </td>
            </tr>            
        </table>

		</form>
	</div>
	
<script>
    function Cancel(){
        window.location="userList.php";
    }
</script>
<script language="javascript">
    function checksubmit(){
        if(document.reg.username.value==""){
            alert("用户名不能为空！");
            document.reg.username.focus();
            return false;
        }
        else if(document.reg.password.value==""){
            alert("密码不能为空！");
            document.reg.password.focus();
            return false;
        }
        else if(document.reg.password.value!=document.reg.password2.value){
            alert("两次输入的密码不一致！请检查。");
            document.reg.password.focus();
            return false;
        }
        else if(document.reg.name.value==""){
            alert("姓名不能为空！");
            document.reg.name.focus();
            return false;
        }  
        return true;  
    }
</script>
</body>
</html>
